<?php namespace App\Http\Controllers\Site;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Item;
use Illuminate\Support\Facades\Cache;

class PolicyController extends Controller{
    public function __construct()
    {
        parent::__construct();
        view()->share('pageName','policiy');
    }
    public function getIndex($type = ""){
        $policies = Item::where('type','policy');
        if("" != $type){
            $policies = $policies->where('kind',$type);
        }
        $policies = $policies->get();
        return view('site.policiy.index',[
            'policies' => $policies,
            'type' => $type,
            'pageName' => 'policy',
        ]);
    }

    public function getDetail($id = 0){
        $model = Item::find($id);
        if("" == $model || $model->type != "policy"){
            abort(404);
        } else {
            return view('site.policiy.detail',[
                'model' => $model,
                'data'  => json_decode($model->content)
            ]);
        }
    }
}